/*
 * 作者：坚果派
 * 公众号：nutpi
 * 电话：17752170152
 * 官网：https://www.nutpi.net/
 */

class Province {
  final String code;
  final String name;
  final List<City> pchilds;

  Province({required this.code, required this.name, required this.pchilds});

  factory Province.fromJson(Map<String, dynamic> json) {
    List<City> cities = [];
    if (json['pchilds'] != null) {
      cities =
          List<City>.from(json['pchilds'].map((city) => City.fromJson(city)));
    }
    return Province(
      code: json['code'],
      name: json['name'],
      pchilds: cities,
    );
  }
}

class City {
  final String code;
  final String name;
  final List<District> cchilds;

  City({required this.code, required this.name, required this.cchilds});

  factory City.fromJson(Map<String, dynamic> json) {
    List<District> districts = [];
    if (json['cchilds'] != null) {
      districts = List<District>.from(
          json['cchilds'].map((district) => District.fromJson(district)));
    }
    return City(
      code: json['code'],
      name: json['name'],
      cchilds: districts,
    );
  }
}

class District {
  final String code;
  final String name;

  District({required this.code, required this.name});

  factory District.fromJson(Map<String, dynamic> json) {
    return District(
      code: json['code'],
      name: json['name'],
    );
  }
}

class Country {
  final String code;
  final String name;
  final List<Province> clist;

  Country({required this.code, required this.name, required this.clist});

  factory Country.fromJson(Map<String, dynamic> json) {
    List<Province> provinces = [];
    if (json['clist'] != null) {
      provinces = List<Province>.from(
          json['clist'].map((province) => Province.fromJson(province)));
    }
    return Country(
      code: json['code'],
      name: json['name'],
      clist: provinces,
    );
  }
}

class ProvinceSimple {
  final String code;
  final String name;

  ProvinceSimple({required this.code, required this.name});

  factory ProvinceSimple.fromJson(Map<String, dynamic> json) {
    return ProvinceSimple(
      code: json['code'],
      name: json['name'],
    );
  }
}

class CitySimple {
  final String code;
  final String name;
  final String provinceCode;

  CitySimple({
    required this.code,
    required this.name,
    required this.provinceCode,
  });

  factory CitySimple.fromJson(Map<String, dynamic> json) {
    return CitySimple(
      code: json['code'],
      name: json['name'],
      provinceCode: json['provinceCode'],
    );
  }
}

class AreaSimple {
  final String code;
  final String name;
  final String provinceCode;
  final String cityCode;

  AreaSimple({
    required this.code,
    required this.name,
    required this.provinceCode,
    required this.cityCode,
  });

  factory AreaSimple.fromJson(Map<String, dynamic> json) {
    return AreaSimple(
      code: json['code'],
      name: json['name'],
      provinceCode: json['provinceCode'],
      cityCode: json['cityCode'],
    );
  }
}

class StreetSimple {
  final String code;
  final String name;
  final String provinceCode;
  final String cityCode;
  final String areaCode;

  StreetSimple({
    required this.code,
    required this.name,
    required this.provinceCode,
    required this.cityCode,
    required this.areaCode,
  });

  factory StreetSimple.fromJson(Map<String, dynamic> json) {
    return StreetSimple(
      code: json['code'],
      name: json['name'],
      provinceCode: json['provinceCode'],
      cityCode: json['cityCode'],
      areaCode: json['areaCode'],
    );
  }
}

class VillageSimple {
  final String code;
  final String name;
  final String provinceCode;
  final String cityCode;
  final String areaCode;
  final String streetCode;

  VillageSimple({
    required this.code,
    required this.name,
    required this.provinceCode,
    required this.cityCode,
    required this.areaCode,
    required this.streetCode,
  });

  factory VillageSimple.fromJson(Map<String, dynamic> json) {
    return VillageSimple(
      code: json['code'],
      name: json['name'],
      provinceCode: json['provinceCode'],
      cityCode: json['cityCode'],
      areaCode: json['areaCode'],
      streetCode: json['streetCode'],
    );
  }
}

class ApiResponse<T> {
  final int code;
  final String msg;
  final T data;

  ApiResponse({required this.code, required this.msg, required this.data});

  factory ApiResponse.fromJson(
      Map<String, dynamic> json, T Function(dynamic) fromJsonT) {
    return ApiResponse<T>(
      code: json['code'],
      msg: json['msg'],
      data: fromJsonT(json['data']),
    );
  }
}
